﻿Public Class frmPICGenerate
    Public strDesciprtion As String = "PIC X(1)"
    Dim mCodeEdit As TextBoxPrj.CodeEditor
    Sub New(ByVal CodeEdit As TextBoxPrj.CodeEditor)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        mCodeEdit = CodeEdit
    End Sub
    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub
#Region "文字列"
    ''' <summary>
    ''' 文字列の長さ
    ''' </summary>
    ''' <remarks></remarks>
    Public strStringLength As Integer
    ''' <summary>
    ''' 文字列の型
    ''' </summary>
    ''' <remarks></remarks>
    Public strStringeMark As Char
    Private Sub radStringType_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
                radKanji.CheckedChanged, radalphabet.CheckedChanged, txtDefaultString.TextChanged, chkJUSTIFIED.CheckedChanged
        RefreshResult()
    End Sub
    Private Sub radDefaultString_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
                        radDefaultString_None.CheckedChanged, radDefaultString_SPACE.CheckedChanged, radDefaultString_USER.CheckedChanged
        txtDefaultString.Enabled = radDefaultString_USER.Checked
        RefreshResult()
    End Sub
    Private Sub nudStringLength_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudStringLength.ValueChanged
        strStringLength = nudStringLength.Value
        RefreshResult()
    End Sub
#End Region
#Region "数字"
    Private Sub radDefaultNumber_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
                    radDefaultNumber_None.CheckedChanged, radDefaultNumber_ZERO.CheckedChanged, radDefaultString_USER.CheckedChanged
        txtDefaultNumber.Enabled = radDefaultNumber_USER.Checked
        RefreshResult()
    End Sub
    Private Sub txtDefaultNumber_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
        txtDefaultNumber.TextChanged, chkOpration.CheckedChanged, nudBeforeV.ValueChanged, nudAfterV.ValueChanged, cmbUSAGE.SelectedIndexChanged
        RefreshResult()
    End Sub
#End Region
#Region "イベント"
    Private Sub PICGenerate_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        lblResult.Text = "結果：" & strDesciprtion
        cmbUSAGE.Items.Add("")
        cmbUSAGE.Items.Add("USAGE BINARY")
        cmbUSAGE.Items.Add("USAGE BIT")
        cmbUSAGE.Items.Add("USAGE COMPUTATIONAL")
        cmbUSAGE.Items.Add("USAGE COMP")
        cmbUSAGE.Items.Add("USAGE COMP-1")
        cmbUSAGE.Items.Add("USAGE COMP-2")
        cmbUSAGE.Items.Add("USAGE COMP-3")
        cmbUSAGE.Items.Add("USAGE COMP-5")
        cmbUSAGE.Items.Add("USAGE DISPLAY")
        cmbUSAGE.Items.Add("USAGE INDEX")
        cmbUSAGE.Items.Add("USAGE POINTER")
        cmbUSAGE.SelectedIndex = 0
    End Sub
    Private Sub radTYPE_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles radString.CheckedChanged, radNumber.CheckedChanged
        grpNumber.Enabled = False
        grpString.Enabled = False
        If radString.Checked Then
            grpString.Enabled = True
        Else
            grpNumber.Enabled = True
        End If
        RefreshResult()
    End Sub
    Private Sub btn_OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_OK.Click
        If CheckInput() = False Then Exit Sub
        Me.DialogResult = Windows.Forms.DialogResult.OK
        If mCodeEdit IsNot Nothing Then
            mCodeEdit.InsertString(strDesciprtion)
        End If
        Me.Close()
    End Sub
    Private Sub btn_Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Cancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
#End Region
#Region "メッソト"
    Sub RefreshResult()
        strDesciprtion = String.Empty
        If radString.Checked Then
            If radalphabet.Checked Then
                strStringeMark = "X"
            Else
                strStringeMark = "N"
            End If
            strDesciprtion = "PIC" & Space(2) & strStringeMark & "(" & strStringLength & ")"

            If chkJUSTIFIED.Checked Then
                strDesciprtion &= Space(2) & "JUSTIFIED RIGHT"
            End If

            If radDefaultString_SPACE.Checked Then
                strDesciprtion &= Space(2) & "VALUE  SPACE"
            End If
            If radDefaultString_USER.Checked And txtDefaultString.Text <> String.Empty Then
                strDesciprtion &= Space(2) & "VALUE" & Space(2) & "'" & txtDefaultString.Text & "'"
            End If
        Else
            If chkOpration.Checked Then
                strDesciprtion = "S"
            End If
            strDesciprtion &= "9(" & Format(nudBeforeV.Value, "0#") & ")"
            strDesciprtion &= "V9(" & Format(nudAfterV.Value, "0#") & ")"
            If radDefaultNumber_ZERO.Checked Then
                strDesciprtion &= Space(2) & "VALUE  ZERO"
            End If
            If radDefaultNumber_USER.Checked And txtDefaultNumber.Text <> String.Empty Then
                strDesciprtion &= Space(2) & "VALUE" & Space(2) & "'" & txtDefaultNumber.Text & "'"
            End If
        End If
        strDesciprtion &= Space(2) & cmbUSAGE.SelectedItem
        lblResult.Text = "結果：" & strDesciprtion
    End Sub
    ''' <summary>
    ''' 入力チェック
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function CheckInput() As Boolean
        Return True
    End Function
#End Region
End Class